package com.ruoyi.system.entity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public enum FormworkDataType {
    //系统字段
    TINYINT("TINYINT", "1"),
    SMALLINT("SMALLINT", "2"),
    MEDIUMINT("MEDIUMINT", "3"),
    INT("INT", "4"),
    BIGINT("BIGINT", "5"),
    FLOAT("FLOAT", "6"),
    DOUBLE("DOUBLE", "7"),
    DECIMAL("DECIMAL", "8"),
    DATE("DATE", "9"),
    TIME("TIME", "10"),
    DATETIME("DATETIME", "11"),
    TIMESTAMP("TIMESTAMP", "12"),
    YEAR("YEAR", "13"),
    CHAR("CHAR", "14"),
    VARCHAR("VARCHAR", "15"),
    TEXT("TEXT", "16"),
    LONGTEXT("LONGTEXT", "17"),
    BLOB("BLOB", "18"),
    ENUM("ENUM", "19"),
    BIT("BIT", "20"),
    BINARY("BINARY", "21"),
    VARBINARY("VARBINARY", "22");
    private String name;
    private String index;

    private FormworkDataType(String name, String index) {
        this.name = name;
        this.index = index;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getIndex() {
        return index;
    }

    public void setIndex(String index) {
        this.index = index;
    }

    public static String getName(String index) {
        for (FormworkDataType platformFree : FormworkDataType.values()) {
            if (index.equals(platformFree.getIndex())) {
                return platformFree.getName();
            }
        }
        return null;
    }


    public static String getIndex(String name) {
        for (FormworkDataType platformFree : FormworkDataType.values()) {
            if (name.equals(platformFree.getName())) {
                return platformFree.getIndex();
            }
        }
        return null;
    }


    /**
     * 将该枚举全部转化成List<Map<String,String>>
     * @param nameKey
     * @param indexKey
     * @return
     */
    public static List<Map<String, String>> toList(String nameKey, String indexKey) {
        List<Map<String, String>> list = new ArrayList<>();
        for (FormworkDataType platformFree : FormworkDataType.values()) {
            Map<String, String> map = new HashMap<>();
            map.put(nameKey, platformFree.getName());
            map.put(indexKey, platformFree.getIndex());
            list.add(map);
        }
        return list;
    }
}
